/*  
* Copyright (c) 2010, James Daniello
* This project is licensed under the 'New BSD' license.
* The full text of the license can be found in the root
* directory under the filename "LICENSE"
*/

package src.engine;

/**
* This class represents an ordered pair. It is stored as a set of co-ordinates rather than
* an angle and magnitude
*/
public class PICAIUVector{

  protected double x, y;
  
  /**
  * Creates a new PICAIUVector with the given values for it's x and y co-ordinates
  */
  public PICAIUVector(double xIn, double yIn){
    x=xIn;
    y=yIn;
  }
  
  /**
  * Creates a new PICAIUVector and initializes it's x and y co-ordinates to 0.
  */
  public PICAIUVector(){
    x=0;
    y=0;
  }
  
  public void setX(double xIn){
    x=xIn;
  }
  
  public void setY(double yIn){
    y=yIn;
  }
  
  public double getX(){
    return x;
  }

  public double getY(){
    return y;
  }
  
  /**
  * Add a vector to this vector given a direction (angle) and magnitutde
  */
  public void add(double direction, double magnitude){
    x+=Math.cos(direction)*magnitude;
    y-=Math.sin(direction)*magnitude;
  }

  /**
  * set this vector given a direction (angle) and magnitutde
  */
  public void set(double direction, double magnitude){
    x=Math.cos(direction)*magnitude;
    y=-Math.sin(direction)*magnitude;
  }
  
  /**
  * Adds a vector to this vector and returns the result.
  * @return returns this vector plus the given vector.
  */
  public PICAIUVector addVector(PICAIUVector vector){
    PICAIUVector toReturn = new PICAIUVector();
    toReturn.setX(x+vector.getX());
    toReturn.setY(y+vector.getY());
    return toReturn;
  }
  
  /**
  * Subtracts a vector from this vector and returns the result
  * @return returns this vector minus the given vector.
  */
  public PICAIUVector subtractVector(PICAIUVector vector){
    PICAIUVector toReturn = new PICAIUVector();
    toReturn.setX(x-vector.getX());
    toReturn.setY(y-vector.getY());
    return toReturn;
  }
  
  /**
  * Add the given amount to this PICAIUVector's x value
  */
  public void addToX(double xPlus){
    x+=xPlus;
  }
  
  /**
  * Add the given amount to this PICAIUVector's y value
  */
  public void addToY(double yPlus){
    y+=yPlus;
  }
  

}